'use strict';

const db = uniCloud.database();
exports.main = async (event, context) => {
	let {relateUuid, wordBankId, studyCount} = event;

	const getRes = await db.collection('memorization').where({
		relateUuid,
		wordBankId
	}).get();
	
	const todayStudyNum = getRes.data[0].todayStudyNum;
	
	const updateRes = await db.collection('memorization').where({
		relateUuid,
		wordBankId
	}).update({
		todayStudyNum: todayStudyNum + studyCount
	});

	return updateRes;
};
